USE [MTNOH_SH_APP]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FUNC_ChangeStr]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[FUNC_ChangeStr]
GO

USE [MTNOH_SH_APP]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


create FUNCTION [dbo].[FUNC_ChangeStr]
(
        @str varchar(1000)
        ,@splitChar char
)
RETURNS @tbl table (rst varchar(50))
AS
BEGIN
	--DECLARE @tbl table (rst varchar(50))

	DECLARE @oneres VARCHAR(100)

	WHILE CHARINDEX(@splitChar,@str) > 0
	BEGIN
		SET @oneres = SUBSTRING(@str,0,CHARINDEX(@splitChar,@str))
		
		insert into @tbl(rst)
		values(@oneres)
		
		SET @str = SUBSTRING(@str,CHARINDEX(@splitChar,@str)+1,LEN(@str))
	END
	
	insert into @tbl(rst)
	values(@str)
	
	return
END

GO




